//
//  API.swift
//  API
//
//  Created by Ben on 2021/9/7.
//

import Foundation
import Alamofire
import UIKit

enum API {
    
    // 更新用户头像
    // 更新用户昵称
    // 。。。等等 其实都是修改用户表的其中一个key对应的value
    
    // user_id用来搜索要修改的用户，value表示要修改的值，user_data_action表示要修改的值对应的key
    case update_user_value(user_id: Int, value: String, user_data_action: Int)
    case goods_category_list(super_id: Int)
    case user_channel_list(user_id: Int)
    case update_user_channel_list(user_id: Int, channel_ids: String)
    case curr_location_category_list(city_name: String)
    
    // MARK: - User相关
    // 该接口用来检查登录账号是否已存在
    case check_register(nick_name: String)
    case login(nick_name: String, pass_word: String)
    
    // init属于系统关键字，如果希望使用这样的关键字作为自己的参数名方法名，使用``包裹即可
    case `init`(token: String)
}

extension API: BaseRequestProtocol {
    
    var parameters: Parameters? {
        var params: Parameters = [:]
        
        switch self {
            
        case let .update_user_value(user_id, value, user_data_action):
            params["user_id"] = user_id
            params["value"] = value
            params["user_data_action"] = user_data_action

        case let .`init`(token):
            params["token"] = token
            
        case let .login(nick_name, pass_word):
            params["nick_name"] = nick_name
            params["pass_word"] = pass_word
        case let .check_register(nick_name):
            params["nick_name"] = nick_name
            
        case let .goods_category_list(super_id):
            params["super_id"] = super_id
        case let .user_channel_list(user_id):
            params["user_id"] = user_id
        case let .update_user_channel_list(user_id, channel_ids):
            params["user_id"] = user_id
            params["channel_ids"] = channel_ids
        case let .curr_location_category_list(city_name):
            params["city_name"] = city_name
        }
        
        return params
    }
    
    var method: HTTPMethod {
        return .post
    }
    
    var path: String {
        
        switch self {
        case .update_user_value:
            return "user_manager/update_user_value"
        case .`init`:
            return "user_manager/inital"
        case .login:
            return "user_manager/login"
        case .check_register:
            return "user_manager/check_register"
        case .goods_category_list:
            return "goods_category/category_list"
        case .user_channel_list:
            return "goods_category/user_channel_list"
        case .update_user_channel_list:
            return "goods_category/update_user_channel_list"
        case .curr_location_category_list:
            return "goods_category/curr_location_category_list"
        }
    }
    
    
}

